package com.example.demo.lc.array;
/**
* @author wzh
* @date 2021/7/21 10:32 上午
* @Description    11. 盛最多水的容器
 * https://leetcode-cn.com/problems/container-with-most-water/
*/
public class LeetCode11 {
    public static void main(String[] args) {
        //int[] height = {1,8,6,2,5,4,8,3,7};
        //int[] height = {1,1};
        //int[] height = {4,3,2,1,4};
        int[] height = {1,2,1};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {
        int i = 0;
        int j = height.length-1;
        int maxArea = 0;
        while (i<j){
            maxArea = Math.max((j-i)*Math.min(height[i],height[j]),maxArea);
            if(height[i] >= height[j]){
                --j;
            }else{
                i++;
            }
        }
        return maxArea;
    }
}
